%%% LaTeX customizations for the diaspora-srd project.
%%%
%%% This file is distributed under the Artistic Licence, v.2.0
%%% You should have received a file containing the license along
%%% with this file; if not see:
%%% http://www.perlfoundation.org/artistic_license_2_0
%%%
\def\VERSION{0.2.0}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{diaspora-srd}
	[2011/06/12 v\VERSION
	Customizations for the Diaspora SRD project]
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% FLAGS FOR DIFFERENT VERSIONS OF THE DOCUMENT
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\RequirePackage{ifthen}
\newboolean{LANDSCAPE}
\setboolean{LANDSCAPE}{false}
\newboolean{SANSSERIF}
\setboolean{SANSSERIF}{true}
\newcommand{\iflandscape}[2]{\ifthenelse{\boolean{LANDSCAPE}}{#1}{#2}}
\newcommand{\ifsansserif}[2]{\ifthenelse{\boolean{SANSSERIF}}{#1}{#2}}
\def\LONGVERSION{%
\VERSION%
\iflandscape{-ls}{-pt}%
\ifsansserif{-ss}{-sf}%
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% for ease of organizing information
\RequirePackage{datatool} 

%%% for nice-looking tables:
\RequirePackage{booktabs}%[2005/04/14] 
\RequirePackage{colortbl}
\RequirePackage{multirow} % for table cells spanning multiple rows

%%% For portrait/landscape compatibility:
\RequirePackage{rotating}

%%% For drawing graphics:
\RequirePackage{tikz}
\RequirePackage{xcolor}[2007/01/21]
% \RequirePackage{graphicx}[1999/02/16]

%%% For including whole PDFs:
\RequirePackage{pdfpages}

%%% Option parsing and command definition
\RequirePackage{xparse}[2008-08-03]
% \RequirePackage{xkeyval}

% \RequirePackage{float}
%%% Wrapping text around floats:
\RequirePackage{wrapfig}

%%% Multicolumn TOC:
% \RequirePackage{multicol}
\RequirePackage[toc]{multitoc}

% \RequirePackage{ifthen}
% \RequirePackage{natbib}
% \RequirePackage{textcomp}

%%% save for last:
\RequirePackage{hyperref}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% DATABASES
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% we load some databases using the datatool package.
\input{db/armour-db}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% GENERAL-PURPOSE MACROS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% shortcut to implementing new length definitions
\newcommand{\definelength}[2]{\newlength{#1}\setlength{#1}{#2}}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% PROJECT-MANAGEMENT MACROS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Shortcuts to places in the project tree
% \def\CHAPTERDIR{chapter}
% \def\INCDIR{inc}
% \def\SIDEBARDIR{sidebar}
% \def\TABLEDIR{tables}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% LAYOUT MACROS
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% font, colour and text layout specifications
% \def\sidebarfont{\sffamily} % from memoir class
%% a dark blue used in various places
\definecolor{niceblue}{rgb}{.199,.129,.467}
%% background colour of shaded sideboxes 
\definecolor{sbbackground}{rgb}{.919,0.913,0.947}
% \definecolor{sbbackground}{rgb}{0.9,0.9,0.9}

%%% widths & lengths
%% width of the margin sidebar space, and usable space inside a sidebar
\setlength{\sidebarwidth}{12ex} % from memoir class
\definelength{\sidebarinnerwidth}{0.95\sidebarwidth}
\setlength{\sidebarhsep}{1ex} % from memoir class
\setlength{\marginparwidth}{\sidebarinnerwidth}
%% width of a full-page sidebar, and the usable width inside it
\definelength{\fullbarwidth}{\textwidth}
\definelength{\fullbarinnerwidth}{0.95\fullbarwidth}
%% width of a half-page sidebar, and the usable width inside it
\definelength{\halfbarwidth}{0.61\textwidth}
\definelength{\halfbarinnerwidth}{0.95\halfbarwidth}


%%% We want a callout box for ``rule'' boxes that pop up in the
%%% margin to give quickly accessible short rules.
%%% This is small, sans-serif, with delineating bars.
%%%
%%% We create a ``calloutbox'' command, and then a ``rulebox''
%%% shortcut.
%%% 
%%% Syntax: \calloutbox{Title}{Body text}
% 
% First some styling and definitions:
\definelength{\CBwidth}{\sidebarinnerwidth}
\def\CBtitlestyle{\color{white}\normalsize\sffamily\bfseries}
\def\CBparstyle{\raggedright\footnotesize\sffamily}
\newcommand{\calloutbox}[2]{%
\begin{marginfigure}%
\scriptsize%
{\color{niceblue}\rule{\CBwidth}{\onelineskip}}\\%
\vspace{-0.9\onelineskip}%
\centerline{{\CBtitlestyle#1}}%
\vspace{0.5\onelineskip}%
\CBparstyle #2 \\%
{\color{niceblue}\rule{\CBwidth}{1pt}\\%
\rule[\onelineskip]{\CBwidth}{2.5pt}}%
\end{marginfigure}%
}%
%

%% convenience shortcut
\newcommand{\rulebox}[1]{\calloutbox{Rule}{#1}}%
% \calloutbox{Rule}{\IfValueTF{#1}{#1}{#2}}
%\textbf{Rule:~} #2  %% TODO remove this inline text

%%% Sidebox float
%%% This is a box that is set apart from the main text, containing
%%% commentary on rules, optional rules, useful tables and so on.
%%% There are two versions, starred and unstarred -- the starred
%%% version spans all columns of the page, while the unstarred
%%% version only fills one. Both versions have a mandatory title
%%% parameter.
%%% Usage:
%%%   \begin{sidebox}{title}
%%%     here is a rundown of stuff.
%%%   \end{sidebox}
%%%
\newlength{\sbwidth} %% sidebox width
\def\sideboxtitlestyle{\large\bfseries}
%% sidebox title text macro
\newcommand{\sideboxtitle}[1]{%
\begin{center}{\sideboxtitlestyle #1}\end{center}%
}
%% Create placeholder box
\makeatletter
\newsavebox{\@sbbox}%
%% Options are:
%% starred version: for one-column layout [?]
%% optional caption
%% mandatory box title text
%% optional label
\DeclareDocumentEnvironment {sidebox} {somo}%
{ % sidebox environment begin block
%% Set width and float type for starred/unstarred version
\IfBooleanTF{#1}%
{\setlength{\sbwidth}{0.9\textwidth}\def\sbfloatname{table*}}%
{\setlength{\sbwidth}{0.95\columnwidth}\def\sbfloatname{table}}%
%% start a content box
\begin{lrbox}{\@sbbox}%
\begin{minipage}{\sbwidth}%
\sideboxtitle{#3}%
}% the content gets saved in the \@sbbox box
{% sidebox environment end block
\end{minipage}%
\end{lrbox}%
% put the contents of the savebox in a table float
\begin{\sbfloatname}[!htb]
\centering
\colorbox{sbbackground}{\usebox{\@sbbox}}
\IfValueT{#2}{\caption{#2}}
\IfValueT{#4}{\label{#4}}
\end{\sbfloatname}%
}%
\makeatother

\makeatletter
\newsavebox{\@shbox}%
\DeclareDocumentEnvironment {shadebox} {om}
{%
\begin{lrbox}{\@shbox}%
\begin{minipage}{#2}%
\IfValueT{#1}{\sideboxtitle{#1}}%
}% the content gets saved in the \@hbbox box
{%
\end{minipage}%
\end{lrbox}%
\colorbox{sbbackground}{\usebox{\@shbox}}%
}
\makeatother

%%% Halfbox float -- currently not working because of weirdness with wrapfig
%% Create placeholder box
\makeatletter
\newsavebox{\@hbbox}%
\newlength{\hbwidth}
%% lines, align, overhang, width, caption, label, title
\DeclareDocumentEnvironment {halfbox} {omomoom}%
% \newenvironment{halfbox}%
{
\setlength\hbwidth{#4}
\begin{wraptable}{#2}[\sidebarwidth]{\hbwidth}%
\centering%
\begin{lrbox}{\@hbbox}
\begin{minipage}{0.8\hbwidth}
\sideboxtitle{#7}
}% the content gets saved in the \@hbbox box
{
\end{minipage}
\end{lrbox}
\colorbox{sbbackground}{\usebox{\@hbbox}}
\IfValueT{#5}{\caption{#5}}
\IfValueT{#6}{\label{#6}}
\end{wraptable}
}%
\makeatother
%
%% The better way?
% \floatstyle{boxed}
% \newfloat{sideboxfloat}{thb}{lsb}[chapter]
% \makeatletter
% \newcommand\fs@shaded{
%
%% What about doing this as a wrapfig?


%%% Wrapping table float
%%% We lay out a table, overlapping the margin by \sidebarwidth, with a shaded 
%%% background.
%%% 
%%% Arguments are:
%%%   alignment (optional, default r)
%%%   margin overlap (optional, default \sidebarwidth)
%%%   float width (optional, default 3\sidebarwidth)
%%%   caption (optional)
%%%   label (optional)
\makeatletter
% \newenvironment{sidetable}[5]%
\DeclareDocumentEnvironment {sidetable} {O{r}O{\sidebarwidth}O{3\sidebarwidth}oo} 
{%
\begin{lrbox}{\@sbbox}%
\begin{minipage}{#3}%
% \sideboxtitle{#3}%
}% the content gets saved in the \@sbbox box
{% sidebox environment end block
\end{minipage}%
\end{lrbox}%
% put the contents of the savebox in a table float
% \begin{wraptable}{#1}[#2]{#3}
\begin{wraptable}{r}[\sidebarwidth]{3\sidebarwidth}%
% \begin{\sbfloatname}[!htb]
\centering
\colorbox{sbbackground}{\usebox{\@sbbox}}
\IfValueT{#4}{\caption{#4}}
\IfValueT{#5}{\label{#5}}
% \end{\sbfloatname}%
\caption{caption here}%
\label{tab:the-ladder}%
\end{wraptable}%
% \caption{#4}
% \IfValueT{#5}{\label{#5}}
% \end{wraptable}
}
\makeatother

%%% TODO: decide on section break format
%%% In some cases it seems like a good idea to start a new page
%%% or column at every section break. We're currently undecided, so
%%% we can easily change that here every time we change our mind.
%% To be inserted before and after each section break
\newcommand{\presection}{\iflandscape{\newpage}{}}
% \newcommand{\presection}{}
\newcommand{\postsection}{}
%% redefine the \section command slightly to use the above
\let\TMPsection\section\relax % placeholder
% \let\TMPsectionstar\section*\relax % placeholder
%
%TODO Enable ``star'' sections
\DeclareDocumentCommand \section {som} {%
\presection%
% \IfValueTF{#1}
% {-star#1-
\IfValueTF{#2}{\TMPsection[#2]{#3}}{\TMPsection{#3}}
% }%
% {-nost#1-\IfValueTF{#2}{\TMPsection[#2]{#3}}{\TMPsection{#3}}}%
\postsection}
%% To be inserted before and after each subsection break
\newcommand{\presubsection}{}
\newcommand{\postsubsection}{}
%% redefine the \subsection command slightly to use the above
\let\TMPsubsection\subsection\relax % placeholder
%
\DeclareDocumentCommand \subsection {som} {%
\presubsection%
\IfValueTF{#2}{\TMPsubsection[#2]{#3}}{\TMPsubsection{#3}}%
\postsubsection}
%

%%% HACK: suppress some over-eager LaTeX warnings
\hfuzz = 1.75pt
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% CHAPTER STYLE
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
%%% Customization of the daleif1 style
\usepackage{color,calc,graphicx,soul}%,fourier}
\makeatletter
\newlength\diaspora@normtxtw
\setlength\diaspora@normtxtw{\textwidth}
\def\myhelvetfont{\def\sfdefault{mdput}}
\newsavebox{\diaspora@chapter}
\newcommand\diaspora@chapter@marker[1][4cm]{%
  \sbox\diaspora@chapter{%
    \resizebox{!}{#1}{\fboxsep=1pt%
      \colorbox{niceblue}{\color{white}\bfseries\sffamily\thechapter}%
    }}%
  \rotatebox{90}{%
    \resizebox{%
      \heightof{\usebox{\diaspora@chapter}}+\depthof{\usebox{\diaspora@chapter}}}%
%     {!}{\scshape\so\@chapapp}}\quad%
    {!}{\rmfamily\scshape\so\@chapapp}}\quad%DLM
  \raisebox{\depthof{\usebox{\diaspora@chapter}}}{\usebox{\diaspora@chapter}}%
}
\newcommand\diaspora@chm[1][4cm]{%
  \sbox\diaspora@chapter{\diaspora@chapter@marker[#1]}%
  \makebox[0pt][l]{% aka \rlap
    \makebox[1cm][r]{\usebox\diaspora@chapter}%
  }}
\makechapterstyle{diaspora}{
  \setlength\beforechapskip{-30pt}
  \setlength\afterchapskip{20pt}
  \setlength\midchapskip{-40pt}
  \renewcommand\chapnamefont{\normalfont\Large\scshape\raggedleft\so}
  \renewcommand\chaptitlefont{\normalfont\HUGE\scshape\color{niceblue}}
%   \renewcommand\chaptitlefont{\normalfont\rmfamily\HUGE\scshape\color{niceblue}}
  \renewcommand\chapternamenum{}
  \renewcommand\printchaptername{}
  \renewcommand\printchapternum{\null\hfill\diaspora@chm[2.5cm]\par}
  \renewcommand\afterchapternum{\par\color{niceblue}\rule{\diaspora@normtxtw}{1px}\vskip\midchapskip}
  \renewcommand\printchaptertitle[1]{\chaptitlefont\raggedright ##1\par}
}
\makeatother
%%%
\chapterstyle{diaspora}
%   \renewcommand\chaptitlefont{\normalfont\HUGE\bfseries\scshape\color{niceblue}}
%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%% Game terms
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\input{lib/sty-game-terms}

% If we need to fix any hyphenation:
\input{inc/hyphenation}
%

